# -*- coding: utf-8 -*-
#
# File: DocumentoTecnico.py
#
# Copyright (c) 2006 by IBICT
# Generator: ArchGenXML Version 1.5.0
#            http://plone.org/products/archgenxml
#
# GNU General Public License (GPL)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
#

__author__ = """IBICT <cadu@ibict.br>"""
__docformat__ = 'plaintext'

from AccessControl import ClassSecurityInfo
from Products.Archetypes.atapi import *
from Products.Archetypes.SQLStorage import *
from Products.SIGFS.config import *

##code-section module-header #fill in your manual code here
from Products.Archetypes import transaction
from Products.CMFCore.utils import getToolByName
##/code-section module-header

schema = Schema((

    TextField(
        name='descricao_documento_tecnico',
        serchable="1",
        widget=TextAreaWidget(
            label="Descrição do Documento Técnico",
            description="Informe uma breve descrição sobre o Documento Técnico.",
            label_msgid='SIGFS_label_descricao_documento_tecnico',
            description_msgid='SIGFS_help_descricao_documento_tecnico',
            i18n_domain='SIGFS',
        )
    ),

    StringField(
        name='categoria',
        index="FieldIndex",
        serchable="1",
        required=1,
        vocabulary='getCategorias',
        enforceVocabulary=1,
        widget=SelectionWidget(
            label="Categoria dos Documentos Técnicos",
            description="Escolha o tipo no qual o Documento será categorizado.",
            format="select",
            label_msgid='SIGFS_label_categoria',
            description_msgid='SIGFS_help_categoria',
            i18n_domain='SIGFS',
        )
    ),

    FileField(
        name='arquivo',
        serchable="1",
        storage=AttributeStorage(),
        widget=FileWidget(
            label="Arquivo",
            description="Se o Documento for constituído de um arquivo, por favor informe-o aqui.",
            label_msgid='SIGFS_label_arquivo',
            description_msgid='SIGFS_help_arquivo',
            i18n_domain='SIGFS',
        )
    ),

    TextField(
        name='corpo_texto_documento',
        allowable_content_types=('text/plain', 'text/structured', 'text/html', 'application/msword',),
        serchable="1",
        default_output_type='text/html',
        widget=RichWidget(
            label="Corpo do texto do Documento",
            description="Informe o corpo do texto do Documento.",
            label_msgid='SIGFS_label_corpo_texto_documento',
            description_msgid='SIGFS_help_corpo_texto_documento',
            i18n_domain='SIGFS',
        )
    ),

),
)

##code-section after-local-schema #fill in your manual code here
##/code-section after-local-schema

DocumentoTecnico_schema = BaseSchema.copy() + \
    schema.copy()

##code-section after-schema #fill in your manual code here
##/code-section after-schema

class DocumentoTecnico(BaseContent):
    """
    """
    security = ClassSecurityInfo()
    __implements__ = (getattr(BaseContent,'__implements__',()),)

    # This name appears in the 'add' box
    archetype_name = 'Documento Técnico'

    meta_type = 'DocumentoTecnico'
    portal_type = 'DocumentoTecnico'
    allowed_content_types = []
    filter_content_types = 0
    global_allow = 0
    content_icon = 'document_icon.gif'
    immediate_view = 'base_view'
    default_view = 'base_view'
    suppl_views = ()
    typeDescription = "Categoria de Documentos Técnicos relacionados às Atividades dos membros."
    typeDescMsgId = 'description_edit_documentotecnico'
    allow_discussion = 1


    actions =  (


       {'action': "string:${object_url}/documento_tecnico_view",
        'category': "object",
        'id': 'view',
        'name': 'View',
        'permissions': ("View",),
        'condition': 'python:1'
       },


    )

    _at_rename_after_creation = True

    schema = DocumentoTecnico_schema

    ##code-section class-header #fill in your manual code here
    ##/code-section class-header

    # Methods

    # Manually created methods

    def getCategorias(self):
        """Retorna a lista de Fundos Setoriais."""
        portal_sigfs = getToolByName(self, 'portal_sigfs')
        result = []
        vocabulary = portal_sigfs.getVocab_categoria()

        for item in vocabulary:
            parts = item.split(';')
            result.append([parts[0], parts[1]])
        return DisplayList(tuple(result))

    security.declarePrivate('_renameAfterCreation')
    def _renameAfterCreation(self, check_auto_id=False):
        """Renomeia o objeto com id numérico sequencial de 6 casas decimais."""
	parent_ids = self.aq_inner.aq_parent.objectIds()
        try:
          new_id = 'dt'+'%0.4i' % len(parent_ids)
          # Usando o portal_factory tem que comitar a subtransacao
          transaction.savepoint(optimistic=True)
	  self.setId(new_id)
	except:
	  new_id = 'dt'+'%0.4i' % len(parent_ids) + str(random.randint(1,1000))
          # Usando o portal_factory tem que comitar a subtransacao
          transaction.savepoint(optimistic=True)
	  self.setId(new_id)



registerType(DocumentoTecnico, PROJECTNAME)
# end of class DocumentoTecnico

##code-section module-footer #fill in your manual code here
##/code-section module-footer



